	var rLoading = document.getElementById("result-loading");
	var rLoadingFail = document.getElementById("result-loading-fail");
	createLoading(rLoading);
	
/*===================getSearchContent===============================*/
	function getSearchContent() {
		var searchContent = "searchContent";
	    var reg = new RegExp("(^|&)" + searchContent + "=([^&]*)(&|$)", "i");  
	    var r = window.location.search.substr(1).match(reg);  
	    if (r != null) 
	    	return unescape(r[2]);
	    return null;  
	}  
	var oSearchContent = getSearchContent();
	console.log(getSearchContent());
/*================== course-box start ====================*/
	
	var isConnecting = false;
	/*var rCourseWrapper = document.getElementById("result-course-wrapper")[0];*/
	var rCourseWrapper = document.getElementById("result-course-wrapper");

	var rArrowLeft = document.getElementById("result-arrow-left");
	var rArrowRight = document.getElementById("result-arrow-right");
	var rCurrentPage = document.getElementById("result-current-page");
	var rTotalPage = document.getElementById("result-total-page");

	//左右箭头点击事件
	rArrowLeft.onclick = rfrontPage;
	rArrowRight.onclick = rnextPage;
	 
	/*------course sort by new or hot end-------*/

	//设置course-wrapper中课程的信息
	//coursesInfor:json
	//setCourseWrapper({"totalPage":12,"1":{"id":1,"type":"HTML/CSS","level":"高级","title":"HTML+CSS基础教程","desc":"HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义","info":999,"price":0}});
	function rSetCourseWrapper(coursesInfor){
		rCourseWrapper.innerHTML = "";
		for(var i=0;i<20;i++){
			var course = coursesInfor[i+1];
			if(course){
				var oCourseCard = createCourseCard();
				oCourseCard.courseCard.href = "course-info.html?courseId="+course.id;
				oCourseCard.courseType.innerText = course.type;
				oCourseCard.courseLevel.innerText = course.degree;
				oCourseCard.courseTitle.innerText = course.coursename;
				oCourseCard.courseDesc.innerText = course.detail;
				oCourseCard.courseInfo.innerText = course.click_nums + "人在学习";
				oCourseCard.coursePrice.innerText = "免费";
				if(!course.price || course.price==0){
					addClass(oCourseCard.coursePrice,"course-card-price-free");
					oCourseCard.coursePrice.innerText = "免费";
				}else{
					oCourseCard.coursePrice.innerText = "￥" + course.price;
				}
				if((i+1)%5 == 0){
					addClass(oCourseCard.wrapper,"last-item");
				}else{
					addClass(oCourseCard.wrapper,"item");
				}
				rCourseWrapper.appendChild(oCourseCard.wrapper);
			}
		}
	}

	/*-------- page bar start ----------*/

	var rPagebar = document.getElementById("result-page-bar");
	var rPageBtn = rPagebar.getElementsByTagName("span");
	var rcurrentPage = 1;
	var rcurrentPageIndex = 1;
	var rtempPage = 1;
	var rtotalPage = 1;

	rPageBtn[0].onclick = function(){
		if(rcurrentPage != 1){
			rtempPage = 1;
			searchCourse();
		}
	}
	rPageBtn[1].onclick = rfrontPage;
	rPageBtn[rPageBtn.length - 2].onclick = rnextPage;
	rPageBtn[rPageBtn.length - 1].onclick = function(){
		if(rcurrentPage != rtotalPage){
			rtempPage = rtotalPage;
			searchCourse();
		}
	}
	for(var i=2;i< rPageBtn.length - 2;i++){
		rPageBtn[i].index = i-1;
		rPageBtn[i].onclick = function(){
			if(this.index != rcurrentPageIndex){
				rtempPage = rcurrentPage + this.index - rcurrentPageIndex;
				searchCourse();
			}
		}
	}
	
	/*-------- page bar end ----------*/
	function rnextPage(){
		if(rcurrentPage != rtotalPage){
			rtempPage = rcurrentPage + 1;
			searchCourse();
		}
	}
	function rfrontPage(){
		if(rcurrentPage != 1){
			rtempPage = rcurrentPage - 1;
			searchCourse();
		}
	}
	function showPage(page){
		//将要显示页面页码所在位置
		//1234 3456 5678 偶数在第二四个位置 奇数在第一三个位置，第一和第四位置特殊
		var index = page%2 == 0?2:3;
		//页码在右边界
		if(rtotalPage - page < 3){
			index = 4 + page - rtotalPage;
		}
		//页码在左边界
		if(page - 1 < 3){
			index = page;
		}
		var tempIndex = index;
		for(var i=0;i<rPageBtn.length-4;i++){
			rPageBtn[i+2].innerText = page - tempIndex + 1;
			tempIndex--;
		}
		rcurrentPage = page;
		removeClass(rPageBtn[rcurrentPageIndex+1],"page-style-clicked");
		addClass(rPageBtn[index+1],"page-style-clicked");
		rcurrentPageIndex = index;
		//显示第一页时上一页按钮无效
		rcurrentPage == 1?addClass(rPageBtn[1],"btn-disable"):removeClass(rPageBtn[1],"btn-disable");
		//显示最后一页时下一页按钮无效
		rcurrentPage == rtotalPage?addClass(rPageBtn[rPageBtn.length - 2],"btn-disable"):removeClass(rPageBtn[rPageBtn.length - 2],"btn-disable");
		rCurrentPage.innerText = rcurrentPage;
		rTotalPage.innerText = rtotalPage;
	}

	function searchCourse(){ 
		if(!isConnecting){
			showLoading();
			var url ="/cyl/getSearchResult";//访问路径
			var data = {
				searchContent : oSearchContent,
				page : rtempPage
			};
			
			ajax({
				type:"post",
				url:url,
				data:data,
				success:searchCourseSuccess,
				fail:searchCourseFail
			});
		}
		isConnecting = true;
	}
	function searchCourseSuccess(response){
		var respJson = JSON.parse(response);
		console.log(respJson);
		hideLoading();
		//设置页码
		 respJson[0]?rtotalPage = respJson[0].rtotalPage : rtotalPage = 1;
		//如果总页数少于4多余按钮隐藏
		for(var i=0;i<rPageBtn.length - 4;i++){
			rPageBtn[i+2].style.display = "inline-block";
		}
		for(var i=rtotalPage;i<rPageBtn.length - 4;i++){
			rPageBtn[i+2].style.display = "none";
		}
		showPage(rtempPage);
		rSetCourseWrapper(respJson);
		isConnecting = false;

	}

	function searchCourseFail(response){
		showLoadingFail();
	}

/*================== course-box end ====================*/
	function showLoading(){
		hideLoadingFail();
		rLoading.style.display = "block";
	}
	function hideLoading(){
		rLoading.style.display = "none";
	}
	function showLoadingFail(){
		hideLoading();
		rLoadingFail.style.display = "block";
	}
	function hideLoadingFail(){
		rLoadingFail.style.display = "none";
	}

	function createLoading(box){
		var transY = getStyle(box,"font-size");
		for(var i=0;i<8;i++){
			var span = document.createElement("span");
			addClass(span,"point");
			box.appendChild(span);
			span.style.transform = "rotateZ("+360/8*i+"deg) translateY("+transY+")";
		}
	}
	searchCourse();

	